package cn.com.inossem.activity;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import cn.com.inossem.base.RequestActivity;
import cn.com.inossem.db.DatabaseHelper;
import cn.com.inossem.model.RetrieveInfoBean;
import cn.com.inossem.model.RetrieveInfoModel;
import cn.com.inossem.requestmanager.WooRequestFactory;
import cn.com.inossem.utils.ActivityStackControlUtil;
import cn.com.inossem.utils.Utils;

import com.foxykeep.datadroid.requestmanager.Request;

/**
 * 
 * 检索单个
 * 
 * <p>
 * detailed comment
 * 
 * @author szc 2015-8-24
 * @see
 * @since 1.0
 */
public class RetrieveItemActivity extends RequestActivity {
	protected Context context = RetrieveItemActivity.this;
	RetrieveInfoBean retrieveinfo;
	public List<RetrieveInfoModel> listproject;
	public List<RetrieveInfoModel> listindustry;
	public List<RetrieveInfoModel> listmodel;
	public List<RetrieveInfoModel> listjobs;
	public List<RetrieveInfoModel> listxingzhi;
	public List<RetrieveInfoModel> projectStatus;
	public List<RetrieveInfoModel> listxuewei;
	public List<RetrieveInfoModel> liststatuzhize;

	public List<List<TextView>> listview;
	// List<View> listtextview;
	LinearLayout linlayer, linlayer1, linlayer2, linlayer3;
	LayoutInflater mInflater;
	TextView wancheng, title, titlename;
	ImageView back;

	int type = 0;
	int itemtype = 0;// 2为行业 5性质
	int position = 0;
	boolean isflag = false;
	boolean isdanxuan = false;

	String idstr = "";
	String[] idlist = { "" };

	public static List<RetrieveInfoModel> xuanzhongProject;// 选中数据
	public static List<RetrieveInfoModel> xuanzhongIndustry;// 选中数据
	public static List<RetrieveInfoModel> xuanzhongModel;// 选中数据
	public static List<RetrieveInfoModel> xuanzhongJobs;// 选中数据
	public static List<RetrieveInfoModel> xuanzhongxingzhi;// 选中数据
	public List<RetrieveInfoModel> xuanzhongprojectStatus;// 选中数据
	public List<RetrieveInfoModel> xuanzhonglistxuewei;// 选中数据
	public List<RetrieveInfoModel> xuanzhongliststatuzhize;// 选中数据

	// private StatusEnum statusEnum;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// setContentView(R.layout.main_tab_layout);
		initView();

	}

	@Override
	public void onDestroy() {
		ActivityStackControlUtil.remove(this);
		super.onDestroy();
	}

	private void initView() {
		isdanxuan = getIntent().getBooleanExtra("isdanxuan", false);
		type = getIntent().getIntExtra("type", 0);
		itemtype = getIntent().getIntExtra("itemtype", 0);
		isflag = getIntent().getBooleanExtra("isflag", false);
		idstr = getIntent().getStringExtra("idstr");
		System.out.println("idstr:" + idstr);
		if (isflag) {
			if (!idstr.equals("") && idstr.contains(","))
				idlist = idstr.split(",");
			else {
				if (!idstr.equals(""))
					idlist[0] = idstr;
			}
		}
		System.out.println("idlist[0]:" + idlist[0]);
		listview = new ArrayList<List<TextView>>();
		xuanzhongProject = new ArrayList<RetrieveInfoModel>();
		xuanzhongIndustry = new ArrayList<RetrieveInfoModel>();
		xuanzhongModel = new ArrayList<RetrieveInfoModel>();
		xuanzhongJobs = new ArrayList<RetrieveInfoModel>();
		xuanzhongxingzhi = new ArrayList<RetrieveInfoModel>();
		xuanzhongprojectStatus = new ArrayList<RetrieveInfoModel>();
		xuanzhonglistxuewei = new ArrayList<RetrieveInfoModel>();
		xuanzhongliststatuzhize = new ArrayList<RetrieveInfoModel>();

		back = (ImageView) this.findViewById(R.id.myback);
		back.setOnClickListener(this);
		wancheng = (TextView) this.findViewById(R.id.wancheng);
		wancheng.setOnClickListener(this);

		title = (TextView) this.findViewById(R.id.title);
		titlename = (TextView) this.findViewById(R.id.titlename);

		listproject = new ArrayList<RetrieveInfoModel>();
		listindustry = new ArrayList<RetrieveInfoModel>();
		listmodel = new ArrayList<RetrieveInfoModel>();
		listjobs = new ArrayList<RetrieveInfoModel>();
		listxingzhi = new ArrayList<RetrieveInfoModel>();
		projectStatus = new ArrayList<RetrieveInfoModel>();
		listxuewei = new ArrayList<RetrieveInfoModel>();
		liststatuzhize = new ArrayList<RetrieveInfoModel>();

		selectData_info(listproject, "t_dictionary", "pid=109");
		selectData_info(listindustry, "t_dictionary", "pid=108");
		selectData_info(listmodel, "t_dictionary", "pid=126");
		selectData_info(listjobs, "t_dictionary", "pid=127");
		selectData_info(listxingzhi, "t_dictionary", "pid=10924");
		selectData_info(projectStatus, "t_dictionary", "pid=10995");
		selectData_info(listxuewei, "t_dictionary", "pid=13220");
		selectData_info(liststatuzhize, "t_dictionary", "pid=10962");

		position = getIntent().getIntExtra("position", 0);

		linlayer = (LinearLayout) this.findViewById(R.id.linlayer);

		switch (type) {
		case 1:// 周期
			title.setText("选择周期");
			titlename.setText("请选择选择周期");
			addView(linlayer, listproject, type, xuanzhongProject);
			break;
		case 2:// 行业
			title.setText("行业领域");
			titlename.setText("请选择行业");
			addView(linlayer, listindustry, type, xuanzhongIndustry);
			break;
		case 3:// 模块
			title.setText("负责模块");
			titlename.setText("您负责的模块");
			addView(linlayer, listmodel, type, xuanzhongModel);
			break;
		case 4:// 岗位
			title.setText("选择岗位");
			titlename.setText("请选择岗位");
			addView(linlayer, listjobs, type, xuanzhongJobs);
			break;
		case 5:// 性质
			title.setText("项目性质");
			titlename.setText("请选择项目性质");
			addView(linlayer, listxingzhi, type, xuanzhongxingzhi);
			break;
		case 6:// 项目地
			title.setText("目前状态");
			titlename.setText("请选择当前状态");
			addView(linlayer, projectStatus, type, xuanzhongprojectStatus);
			break;
		case 7:// 学位
			title.setText("学位");
			titlename.setText("请选择学位");
			System.out.println("listxuewei.size():" + listxuewei.size());
			addView(linlayer, listxuewei, type, xuanzhonglistxuewei);
			break;
		case 8:// 岗位职责
			title.setText("选择岗位职责");
			titlename.setText("请选岗位职责");
			addView(linlayer, liststatuzhize, type, xuanzhongliststatuzhize);
			break;
		default:
			break;
		}

	}

	private void addView(LinearLayout layer, List<RetrieveInfoModel> listrim,
			final int type, List<RetrieveInfoModel> selectrim) {
		List<TextView> listText = new ArrayList<TextView>();

		List<View> listtextview = new ArrayList<View>();
		for (int i = 0; i < listrim.size(); i++) {
			mInflater = LayoutInflater.from(this);
			View view = mInflater.inflate(R.layout.textviewitem, null);
			String text = listrim.get(i).getName();
			TextView textview = (TextView) view.findViewById(R.id.textview);

			if (listrim.get(i).getIsselected() == 0) {
				// if (listrim.get(i).getIsselected() == 0) {
				textview.setTextColor(Color.rgb(66, 66, 66));
				textview.setBackgroundResource(R.drawable.weixuanzhong);
			} else {
				textview.setTextColor(Color.rgb(255, 255, 255));
				textview.setBackgroundResource(R.drawable.xuanzhong);
			}

			textview.setText(text);
			textview.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					TextView tv = (TextView) v;
					int posion = (Integer) tv.getTag();
					switch (type) {
					case 1:
						if (listproject.get(posion).getIsselected() == 0) {

							listproject.get(posion).setIsselected(1);
							tv.setTextColor(Color.rgb(255, 255, 255));
							tv.setBackgroundResource(R.drawable.xuanzhong);
							if (!xuanzhongProject.contains(listproject
									.get(posion))) {
								xuanzhongProject.add(listproject.get(posion));
							}
						} else {
							listproject.get(posion).setIsselected(0);
							tv.setTextColor(Color.rgb(66, 66, 66));
							tv.setBackgroundResource(R.drawable.weixuanzhong);
							if (xuanzhongProject.contains(listproject
									.get(posion))) {
								xuanzhongProject.remove(listproject.get(posion));
							}
						}
						break;
					case 2:
						if (listindustry.get(posion).getIsselected() == 0) {
							if (isdanxuan) {
								for (int i = 0; i < listindustry.size(); i++) {
									listindustry.get(i).setIsselected(0);
									listview.get(0)
											.get(i)
											.setTextColor(Color.rgb(66, 66, 66));
									listview.get(0)
											.get(i)
											.setBackgroundResource(
													R.drawable.weixuanzhong);
								}
								xuanzhongIndustry = new ArrayList<RetrieveInfoModel>();
							}
							listindustry.get(posion).setIsselected(1);
							tv.setTextColor(Color.rgb(255, 255, 255));
							tv.setBackgroundResource(R.drawable.xuanzhong);
							if (!xuanzhongIndustry.contains(listindustry
									.get(posion))) {
								xuanzhongIndustry.add(listindustry.get(posion));
							}

						} else {
							listindustry.get(posion).setIsselected(0);
							tv.setTextColor(Color.rgb(66, 66, 66));
							tv.setBackgroundResource(R.drawable.weixuanzhong);
							if (xuanzhongIndustry.contains(listindustry
									.get(posion))) {
								xuanzhongIndustry.remove(listindustry
										.get(posion));
							}
						}
						break;
					case 3:
						if (listmodel.get(posion).getIsselected() == 0) {
							if (isdanxuan) {
								for (int i = 0; i < listmodel.size(); i++) {
									listmodel.get(i).setIsselected(0);
									listview.get(0)
											.get(i)
											.setTextColor(Color.rgb(66, 66, 66));
									listview.get(0)
											.get(i)
											.setBackgroundResource(
													R.drawable.weixuanzhong);
								}
								xuanzhongModel = new ArrayList<RetrieveInfoModel>();
							}
							listmodel.get(posion).setIsselected(1);
							tv.setTextColor(Color.rgb(255, 255, 255));
							tv.setBackgroundResource(R.drawable.xuanzhong);
							if (!xuanzhongModel.contains(listmodel.get(posion))) {
								xuanzhongModel.add(listmodel.get(posion));
							}
						} else {
							listmodel.get(posion).setIsselected(0);
							tv.setTextColor(Color.rgb(66, 66, 66));
							tv.setBackgroundResource(R.drawable.weixuanzhong);
							if (xuanzhongModel.contains(listmodel.get(posion))) {
								xuanzhongModel.remove(listmodel.get(posion));
							}
						}
						break;
					case 4:
						if (listjobs.get(posion).getIsselected() == 0) {
							if (isdanxuan) {
								for (int i = 0; i < listjobs.size(); i++) {
									listjobs.get(i).setIsselected(0);
									listview.get(0)
											.get(i)
											.setTextColor(Color.rgb(66, 66, 66));
									listview.get(0)
											.get(i)
											.setBackgroundResource(
													R.drawable.weixuanzhong);
								}
								xuanzhongJobs = new ArrayList<RetrieveInfoModel>();
							}
							listjobs.get(posion).setIsselected(1);
							tv.setTextColor(Color.rgb(255, 255, 255));
							tv.setBackgroundResource(R.drawable.xuanzhong);
							if (!xuanzhongJobs.contains(listjobs.get(posion))) {
								xuanzhongJobs.add(listjobs.get(posion));
							}
						} else {
							listjobs.get(posion).setIsselected(0);
							tv.setTextColor(Color.rgb(66, 66, 66));
							tv.setBackgroundResource(R.drawable.weixuanzhong);
							if (xuanzhongJobs.contains(listjobs.get(posion))) {
								xuanzhongJobs.remove(listjobs.get(posion));
							}
						}
						break;

					case 5:
						if (listxingzhi.get(posion).getIsselected() == 0) {
							if (isdanxuan) {
								for (int i = 0; i < listxingzhi.size(); i++) {
									listxingzhi.get(i).setIsselected(0);
									listview.get(0)
											.get(i)
											.setTextColor(Color.rgb(66, 66, 66));
									listview.get(0)
											.get(i)
											.setBackgroundResource(
													R.drawable.weixuanzhong);
								}
								xuanzhongxingzhi = new ArrayList<RetrieveInfoModel>();
							}
							listxingzhi.get(posion).setIsselected(1);
							tv.setTextColor(Color.rgb(255, 255, 255));
							tv.setBackgroundResource(R.drawable.xuanzhong);
							if (!xuanzhongxingzhi.contains(listxingzhi
									.get(posion))) {
								xuanzhongxingzhi.add(listxingzhi.get(posion));
							}
						} else {
							listxingzhi.get(posion).setIsselected(0);
							tv.setTextColor(Color.rgb(66, 66, 66));
							tv.setBackgroundResource(R.drawable.weixuanzhong);
							if (xuanzhongxingzhi.contains(listxingzhi
									.get(posion))) {
								xuanzhongxingzhi.remove(listxingzhi.get(posion));
							}
						}
						break;
					case 6:
						if (projectStatus.get(posion).getIsselected() == 0) {
							System.out.println("xuanzhongprojectStatus:"
									+ xuanzhongprojectStatus.size());
							for (int i = 0; i < projectStatus.size(); i++) {
								projectStatus.get(i).setIsselected(0);
								listview.get(0).get(i)
										.setTextColor(Color.rgb(66, 66, 66));
								listview.get(0)
										.get(i)
										.setBackgroundResource(
												R.drawable.weixuanzhong);
							}
							xuanzhongprojectStatus = new ArrayList<RetrieveInfoModel>();
							projectStatus.get(posion).setIsselected(1);
							tv.setTextColor(Color.rgb(255, 255, 255));
							tv.setBackgroundResource(R.drawable.xuanzhong);

							if (!xuanzhongprojectStatus.contains(projectStatus
									.get(posion))) {
								xuanzhongprojectStatus.add(projectStatus
										.get(posion));
							}
						} else {
							projectStatus.get(posion).setIsselected(0);
							tv.setTextColor(Color.rgb(66, 66, 66));
							tv.setBackgroundResource(R.drawable.weixuanzhong);
							if (xuanzhongprojectStatus.contains(projectStatus
									.get(posion))) {
								xuanzhongprojectStatus.remove(projectStatus
										.get(posion));
							}
						}
					case 7:
						if (listxuewei.get(posion).getIsselected() == 0) {
							if (isdanxuan) {
								for (int i = 0; i < listxuewei.size(); i++) {
									listxuewei.get(i).setIsselected(0);
									listview.get(0)
											.get(i)
											.setTextColor(Color.rgb(66, 66, 66));
									listview.get(0)
											.get(i)
											.setBackgroundResource(
													R.drawable.weixuanzhong);
								}
								xuanzhonglistxuewei = new ArrayList<RetrieveInfoModel>();
							}
							listxuewei.get(posion).setIsselected(1);
							tv.setTextColor(Color.rgb(255, 255, 255));
							tv.setBackgroundResource(R.drawable.xuanzhong);
							if (!xuanzhonglistxuewei.contains(listxuewei
									.get(posion))) {
								xuanzhonglistxuewei.add(listxuewei.get(posion));
							}
						} else {
							listxuewei.get(posion).setIsselected(0);
							tv.setTextColor(Color.rgb(66, 66, 66));
							tv.setBackgroundResource(R.drawable.weixuanzhong);
							if (xuanzhonglistxuewei.contains(listxuewei
									.get(posion))) {
								xuanzhonglistxuewei.remove(listxuewei
										.get(posion));
							}
						}
						break;
					case 8:
						if (liststatuzhize.get(posion).getIsselected() == 0) {
							if (isdanxuan) {
								for (int i = 0; i < liststatuzhize.size(); i++) {
									listjobs.get(i).setIsselected(0);
									listview.get(0)
											.get(i)
											.setTextColor(Color.rgb(66, 66, 66));
									listview.get(0)
											.get(i)
											.setBackgroundResource(
													R.drawable.weixuanzhong);
								}
								xuanzhongliststatuzhize = new ArrayList<RetrieveInfoModel>();
							}
							liststatuzhize.get(posion).setIsselected(1);
							tv.setTextColor(Color.rgb(255, 255, 255));
							tv.setBackgroundResource(R.drawable.xuanzhong);
							if (!xuanzhongliststatuzhize
									.contains(liststatuzhize.get(posion))) {
								xuanzhongliststatuzhize.add(liststatuzhize
										.get(posion));
							}
						} else {
							liststatuzhize.get(posion).setIsselected(0);
							tv.setTextColor(Color.rgb(66, 66, 66));
							tv.setBackgroundResource(R.drawable.weixuanzhong);
							if (xuanzhongliststatuzhize.contains(liststatuzhize
									.get(posion))) {
								xuanzhongliststatuzhize.remove(liststatuzhize
										.get(posion));
							}
						}
						break;

					default:
						break;
					}

				}
			});

			Paint paint = new Paint();
			paint.setTextSize(textview.getTextSize());
			float size = paint.measureText(textview.getText().toString());
			view.setTag((int) size + Utils.dip2px(this, 10 * 2 + 10));
			textview.setTag(i);
			listText.add(textview);
			listtextview.add(view);
		}
		listview.add(listText);

		int j = 0;
		LinearLayout llayout = null;
		int MaxWidth = MainActivity.widthPixels - Utils.dip2px(this, 20);
		int temporarywidth = 0;
		while (true) {
			View view = null;
			int tagwidth = 0;
			if (j == listtextview.size()) {
				return;
			} else {
				view = listtextview.get(j);

				tagwidth = (Integer) view.getTag();
			}
			if (j == 0) {
				llayout = new LinearLayout(this);
			}
			System.out.println("textview:" + tagwidth + "temporarywidth:"
					+ temporarywidth + "MaxWidth:" + MaxWidth);
			if (tagwidth + temporarywidth + 40 < MaxWidth) {
				temporarywidth += tagwidth;
				llayout.addView(view);
			} else {
				layer.addView(llayout);

				LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
						LinearLayout.LayoutParams.MATCH_PARENT,
						LinearLayout.LayoutParams.WRAP_CONTENT);
				layoutParams.setMargins(0, 15, 0, 0);

				llayout = new LinearLayout(this);
				llayout.setLayoutParams(layoutParams);
				temporarywidth = (Integer) view.getTag();

				llayout.addView(view);
			}

			if (j == listtextview.size() - 1) {
				layer.addView(llayout);
			}
			j++;
		}
	}

	private void selectData_info(List<RetrieveInfoModel> listModel,
			String tabname, String selection) {

		DatabaseHelper dh = new DatabaseHelper(this);
		SQLiteDatabase db = dh.getReadableDatabase();
		Cursor cursor = db.query(tabname, null, selection, null, null, null,
				null);
		while (cursor.moveToNext()) {
			RetrieveInfoModel rim = new RetrieveInfoModel();
			int id = cursor.getInt(cursor.getColumnIndex("id"));
			String name = cursor.getString(cursor.getColumnIndex("name_cn"));
			rim.setId(id);
			rim.setName(name);
			rim.setIsselected(0);
			if (isflag && idlist.length > 0 && !idlist[0].equals("")) {
				for (int i = 0; i < idlist.length; i++) {
					if (id == Integer.parseInt(idlist[i])) {
						rim.setIsselected(1);
						switch (type) {
						case 2:
							xuanzhongIndustry.add(rim);
							break;
						case 3:
							xuanzhongModel.add(rim);
							break;
						case 4:
							xuanzhongJobs.add(rim);
							break;
						case 6:
							xuanzhongprojectStatus.add(rim);
							break;
						case 8:
							xuanzhongliststatuzhize.add(rim);
							break;
						default:
							break;
						}

					}

				}
			} else {
				rim.setIsselected(0);
			}
			listModel.add(rim);
		}
		if (type == 7)
			System.out.println("7777listModel.size():" + listModel.size());
		cursor.close();
		db.close();
		dh.close();

	}

	@Override
	public Request getInitialRequest() {
		return null;

	}

	@Override
	public void onRequestSucess(Request request, Bundle bundle) {

	}

	@Override
	public void onRequestError(int exceptionType) {

	}

	public int getContentViewId() {
		return R.layout.retrieveitem_layout;

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.myback:
			Intent intent = new Intent();
			intent.putExtra("name", "");
			intent.putExtra("num", "");
			intent.putExtra("result", "");
			setResult(0, intent);
			finish();
			break;
		case R.id.wancheng:
			intent = new Intent();
			switch (type) {
			case 1:
				if (xuanzhongProject.size() > 0) {
					intent.putExtra("name", xuanzhongProject.get(0).getName());
					if (xuanzhongProject.size() > 1)
						intent.putExtra("num", "等" + xuanzhongProject.size()
								+ "个");
					else
						intent.putExtra("num", "");
					intent.putExtra("result",
							resutData(intent, xuanzhongProject));
				} else {
					intent.putExtra("name", "全部");
					intent.putExtra("num", "");
					intent.putExtra("result", "");
				}
				break;
			case 2:
				if (itemtype == 2) {

					if (xuanzhongIndustry.size() > 0) {
						intent.putExtra("name", xuanzhongIndustry.get(0)
								.getName());
						intent.putExtra("id", xuanzhongIndustry.get(0).getId());
					} else {
						intent.putExtra("name", "");
						intent.putExtra("id", 0);
					}
				} else {
					if (isflag) {
						String value = "";
						if (xuanzhongIndustry.size() > 0) {
							intent.putExtra("name", xuanzhongIndustry.get(0)
									.getName());
							value = xuanzhongIndustry.get(0).getId() + "";

							if (xuanzhongIndustry.size() > 1) {
								intent.putExtra("num",
										"等" + xuanzhongIndustry.size() + "个");
								for (int i = 1; i < xuanzhongIndustry.size(); i++) {
									value += ","
											+ xuanzhongIndustry.get(i).getId();
								}
							} else
								intent.putExtra("num", "");

							intent.putExtra("value", value);
							intent.putExtra("result",
									resutData(intent, xuanzhongIndustry));

						} else {
							intent.putExtra("name", "");
							intent.putExtra("num", "");
							intent.putExtra("value", value);
						}

						launchRequest(WooRequestFactory.updatePersonal(
								"industry", value));
					} else {
						if (xuanzhongIndustry.size() > 0) {
							intent.putExtra("name", xuanzhongIndustry.get(0)
									.getName());
							if (xuanzhongIndustry.size() > 1)
								intent.putExtra("num",
										"等" + xuanzhongIndustry.size() + "个");
							else
								intent.putExtra("num", "");
							intent.putExtra("result",
									resutData(intent, xuanzhongIndustry));
						} else {
							intent.putExtra("name", "全部");
							intent.putExtra("num", "");
							intent.putExtra("result", "");
						}
					}
				}
				break;
			case 3:
				if (itemtype == 3) {
					if (xuanzhongModel.size() > 0) {
						intent.putExtra("name", xuanzhongModel.get(0).getName());
						intent.putExtra("id", xuanzhongModel.get(0).getId());
					} else {
						intent.putExtra("name", "");
						intent.putExtra("id", 0);
					}
				} else {
					if (xuanzhongModel.size() > 0) {
						intent.putExtra("name", xuanzhongModel.get(0).getName());
						if (xuanzhongModel.size() > 1)
							intent.putExtra("num", "等" + xuanzhongModel.size()
									+ "个");
						else
							intent.putExtra("num", "");
						intent.putExtra("result",
								resutData(intent, xuanzhongModel));
					} else {
						intent.putExtra("name", "全部");
						intent.putExtra("num", "");
						intent.putExtra("result", "");
					}
				}
				break;
			case 4:
				if (itemtype == 4) {
					if (xuanzhongJobs.size() > 0) {
						intent.putExtra("name", xuanzhongJobs.get(0).getName());
						intent.putExtra("id", xuanzhongJobs.get(0).getId());
					} else {
						intent.putExtra("name", "");
						intent.putExtra("id", 0);
					}
				} else {
					if (xuanzhongJobs.size() > 0) {
						intent.putExtra("name", xuanzhongJobs.get(0).getName());
						if (xuanzhongJobs.size() > 1)
							intent.putExtra("num", "等" + xuanzhongJobs.size()
									+ "个");
						else
							intent.putExtra("num", "");
						intent.putExtra("result",
								resutData(intent, xuanzhongJobs));
					} else {
						intent.putExtra("id", 0);
						intent.putExtra("name", "全部");
						intent.putExtra("num", "");
						intent.putExtra("result", "");
					}
				}
				break;
			case 5:
				if (itemtype == 5) {
					if (xuanzhongxingzhi.size() > 0) {
						intent.putExtra("name", xuanzhongxingzhi.get(0)
								.getName());
						intent.putExtra("id", xuanzhongxingzhi.get(0).getId());
					} else {
						intent.putExtra("name", "");
						intent.putExtra("id", 0);
					}
				} else {
					if (xuanzhongxingzhi.size() > 0) {
						intent.putExtra("name", xuanzhongxingzhi.get(0)
								.getName());
						if (xuanzhongxingzhi.size() > 1)
							intent.putExtra("num",
									"等" + xuanzhongxingzhi.size() + "个");
						else
							intent.putExtra("num", "");
						intent.putExtra("result",
								resutData(intent, xuanzhongxingzhi));
					} else {
						intent.putExtra("name", "全部");
						intent.putExtra("num", "");
						intent.putExtra("result", "");
					}
				}
				break;
			case 6:
				if (isflag) {
					String value = "0";
					if (xuanzhongprojectStatus.size() > 0) {
						intent.putExtra("name", xuanzhongprojectStatus.get(0)
								.getName());
						value = xuanzhongprojectStatus.get(0).getId() + "";

						if (xuanzhongprojectStatus.size() > 1) {
							intent.putExtra("num",
									"等" + xuanzhongprojectStatus.size() + "个");
							for (int i = 1; i < xuanzhongprojectStatus.size(); i++) {
								value += ","
										+ xuanzhongprojectStatus.get(i).getId();
							}
						} else
							intent.putExtra("num", "");
						intent.putExtra("id", xuanzhongprojectStatus.get(0)
								.getId());
						intent.putExtra("value", value);
						intent.putExtra("result",
								resutData(intent, xuanzhongprojectStatus));

					} else {
						intent.putExtra("id", 0);
						intent.putExtra("name", "");
						intent.putExtra("num", "");
						intent.putExtra("value", value);
					}

					launchRequest(WooRequestFactory.updatePersonal(
							"projectStatus", value));
				}
				break;
			case 7:
				if (itemtype == 7) {
					if (xuanzhonglistxuewei.size() > 0) {
						intent.putExtra("name", xuanzhonglistxuewei.get(0)
								.getName());
						intent.putExtra("id", xuanzhonglistxuewei.get(0)
								.getId());
					} else {
						intent.putExtra("name", "");
						intent.putExtra("id", 0);
					}
				} else {
					if (xuanzhonglistxuewei.size() > 0) {
						intent.putExtra("name", xuanzhonglistxuewei.get(0)
								.getName());
						if (xuanzhonglistxuewei.size() > 1)
							intent.putExtra("num",
									"等" + xuanzhonglistxuewei.size() + "个");
						else
							intent.putExtra("num", "");
						intent.putExtra("result",
								resutData(intent, xuanzhonglistxuewei));
					} else {
						intent.putExtra("name", "全部");
						intent.putExtra("num", "");
						intent.putExtra("result", "");
					}
				}
				break;
			case 8:
				if (itemtype == 8) {
					if (xuanzhongliststatuzhize.size() > 0) {
						intent.putExtra("name", xuanzhongliststatuzhize.get(0)
								.getName());
						intent.putExtra("id", xuanzhongliststatuzhize.get(0)
								.getId());
					} else {
						intent.putExtra("name", "");
						intent.putExtra("id", 0);
					}
				} else {
					if (xuanzhongliststatuzhize.size() > 0) {
						intent.putExtra("name", xuanzhongliststatuzhize.get(0)
								.getName());
						if (xuanzhongliststatuzhize.size() > 1)
							intent.putExtra("num", "等"
									+ xuanzhongliststatuzhize.size() + "个");
						else
							intent.putExtra("num", "");
						intent.putExtra("result",
								resutData(intent, xuanzhongliststatuzhize));
					} else {
						intent.putExtra("id", 0);
						intent.putExtra("name", "");
						intent.putExtra("num", "");
						intent.putExtra("result", "");
					}
				}
				break;
			default:
				break;
			}

			setResult(type, intent);
			finish();
			break;

		default:
			break;
		}
	}

	public String resutData(Intent intent, List<RetrieveInfoModel> list) {
		String str = list.get(0).getId() + "";
		for (int i = 1; i < list.size(); i++) {
			str += "," + list.get(i).getId();
		}

		return str;
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {

		if (keyCode == KeyEvent.KEYCODE_BACK) {
			Intent intent = new Intent();
			intent.putExtra("name", "全部");
			intent.putExtra("num", "");
			intent.putExtra("result", "");
			setResult(7, intent);
			finish();
			return true;

		}

		return super.onKeyDown(keyCode, event);

	}

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		switch (resultCode) { // resultCode为回传的标记，我在B中回传的是RESULT_OK
		case 1:
			setResult(1);
			finish();
		default:
			break;
		}
	}
}
